package apis

import (
	m "web_api_go/models"
	"fmt"

	"github.com/gin-gonic/gin"
)


func IndexApi(c *gin.Context) {
	//c.String(http.StatusOK, "It works")

	/*
		if err != nil {
			c.JSON(200, gin.H{"message": "It not works"})
			return
		}
	*/
	c.JSON(200, gin.H{"message": "It works"})
}

func PostTasksApi(c *gin.Context) {
	verify_key := c.Request.Header.Get("verification-key")

	if verify_key == "7201a06436fd56" {
		//data := c.PostForm("data")
		d, err := c.GetRawData()
		if err != nil {
			fmt.Println(err)
			c.JSON(503, gin.H{"message": "the post data occur error"})
		}
		key := "playbook_tasks_queue"
		//err = m.Lpushdata(string(d))
		err = m.Lpushdata(key, string(d))
		if err != nil {
			c.JSON(503, gin.H{"message": "push data failed"})
			return
		}
		c.JSON(200, gin.H{"message": "post data sucessfully"})
		return
	} else {
		c.JSON(503, gin.H{"message": "verification-key is error"})
		return
	}
}
